//
//  main.c
//  C_8高级函数
//
//  Created by Robin on 16/3/18.
//  Copyright © 2016年 cnbm. All rights reserved.
//

#include <stdio.h>
#include <string.h>

void find(int(*match)(char *s));
int sport_art (char *s);
int sport_art_dining (char *s);

// 函数指针
char *man[] = {
    " William: SBM GSOH like sports,TV,dining",
    " Matt: SWN NS like art,movies,theater",
    " Lius: SLD NM like books,theater,art",
    " Mike: DWM DS likes trucks, sports and bieber",
    " Peter: SAM likes chess, working out and art",
    " Josh: SJM likes sports",
    " Jed: DBM likes theater, books and dining"
};

int main(int argc, const char * argv[]) {
    
    //qsort
    find(sport_art);
    find(sport_art_dining);
    return 0;
}

void find(int(*match)(char *s)){
    int NUM_ADS = 7;
    for (int i=0; i<NUM_ADS; i++) {
        if (match(man[i])) {
            puts("--------------");
            
            printf("ADS IS %s\n",man[i]);
            
            puts("--------------");

        }
    }
}

int sport_art (char *s){
    return strstr(s, "sports") && !strstr(s, "bieber");
}

int sport_art_dining (char *s){
    return strstr(s, "sports") || strstr(s, "art") || strstr(s, "dining");
}
